const ApiConfig = require("../../config/api-config");
const { get } = require("../../utils/request");

// 扫码结果弹窗组件
Component({
  properties: {
    // 弹窗显示状态
    visible: {
      type: Boolean,
      value: false
    },
    // 扫码结果
    drugInfo: {
      type: Object,
      value: {}
    }
  },

  data: {
    // 按钮按下状态
    closePressed: false,
    copyPressed: false,
    sharePressed: false
  },

  methods: {
    // 点击遮罩关闭
    onMaskTap() {
      this.onClose();
    },


    // 关闭弹窗
    onClose() {
      this.triggerEvent('close');
    },

    // 分享结果
    async onShare() {
      const url = ApiConfig.server.baseUrl+ApiConfig.endpoints.uploadCode;
      const data = {
        code:this.properties.drugInfo.code
      }
      const res = await get(url,data)
      if(res.code === 200){
        wx.showToast({ title: '已上报', icon: 'success' });
      }
    },

    // 阻止事件冒泡
    stopPropagation() {
      // 空函数，阻止点击事件冒泡
    },

    // 触摸事件处理
    onCloseTouchStart() {
      this.setData({ closePressed: true });
    },

    onCloseTouchEnd() {
      this.setData({ closePressed: false });
    },

    onCopyTouchStart() {
      this.setData({ copyPressed: true });
    },

    onCopyTouchEnd() {
      this.setData({ copyPressed: false });
    },

    onShareTouchStart() {
      this.setData({ sharePressed: true });
    },

    onShareTouchEnd() {
      this.setData({ sharePressed: false });
    }
  }
});